﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

namespace Krist_em_up.Music
{
    /// <summary>
    /// Handle ponctuals sounds over the game
    /// </summary>
    static class Sounds
    {
        /// <summary>
        /// Bullet shot
        /// </summary>
        static SoundEffect Shoot;
        /// <summary>
        /// Kris' jump sound
        /// </summary>
        static SoundEffect Jump;
        
        /// <summary>
        /// User-set volume
        /// </summary>
        static float volume;

        static bool initialized;

        /// <summary>
        /// Initialize the several sounds
        /// </summary>
        /// <param name="Content">Content manager</param>
        public static void Initialize(ContentManager Content)
        {
            if (!initialized)
            {
                try
                {
                    Shoot = Content.Load<SoundEffect>("sound/shoot");
                    Jump = Content.Load<SoundEffect>("sound/jump");
                    initialized = true;
                    volume = 1;
                }
                catch (Exception)
                {

                }
            }
        }

        /// <summary>
        /// Play default shoot sound
        /// </summary>
        public static void PlayShoot()
        {
            try
            {
                if (initialized)
                    Shoot.Play(0.1f * volume, 0f, 0f);
            }
            catch { }
        }
        /// <summary>
        /// Play default jump sound
        /// </summary>
        public static void PlayJump()
        {
            try
            {
                if (initialized)
                    Jump.Play(1f * volume, 0f, 0f);
            }
            catch { }
        }
        /// <summary>
        /// Play default shoot sound
        /// </summary>
        /// <param name="position">
        /// Float value ranging from -1f to 1f representing the position 
        /// where the shoot is made regarding to origin
        /// </param>
        public static void PlayShoot(float position)
        {
            if (initialized)
                Shoot.Play(0.1f * volume, 0f, position);
        }
    }
}
